function loadXMLDocSquad(url, game, popup) 
{
	var req;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange(req, game, popup, false);
		req.open("GET", url, true);
		req.send(null);
		// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange(req, game, popup, false);
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processReqChange(req, game, popup, process) 
{
	if (!process) 
		return function() { processReqChange(req, game, popup, true); };


	var span = game.getElementsByTagName("span")[0];

	if (req.readyState == 1)
	{
		span.innerHTML = "Wait...";
		span.onclick = null;
	}

	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			// ...processing statements go here...
			/*
			response  = req.responseXML.documentElement;
			method    =
				response.getElementsByTagName('method')[0].firstChild.data;
			result    = 
				response.getElementsByTagName('result')[0].firstChild.data;
			eval(method + '(\'\', result)');
			*/
			var div = getElementsByClass(game, "game_squad")[0];
			if (!div) div = document.createElement("div");
			div.innerHTML = req.responseText;
			div.className = "game_squad";
			game.appendChild(div);
			span.innerHTML = "Close squad";
			span.onclick = function() { close_squad(game); };
		} else {
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
		if (popup)
		{
			popup.document.body.innerHTML = "teste";
			popup.close();
			popup = null;
		}
	}
}

function write_squad(game, game_id, popup)
{
	if (game)
		loadXMLDocSquad("game_squad.php?game="+game_id, game, popup);
}

function close_squad(game)
{
	var div = game.getElementsByTagName("div")[0];
	div.style.display = "none";

	var span = game.getElementsByTagName("span")[0];
	span.innerHTML = "Show squad";
	span.onclick = function() { show_squad(game); };
}

function show_squad(game)
{
	var div = game.getElementsByTagName("div")[0];
	div.style.display = "block";

	var span = game.getElementsByTagName("span")[0];
	span.innerHTML = "Close squad";
	span.onclick = function() { close_squad(game); };
}
